package com.gmall.rabbitmq.producer.controller;

import com.gmall.rabbitmq.config.RabbitMQConfig_DeadLetter;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("deadletter")
public class DeadLetterController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @PostMapping("nack")
    public String producerMessage1(){

        rabbitTemplate.convertAndSend(RabbitMQConfig_DeadLetter.Exchange_Business_1,
                RabbitMQConfig_DeadLetter.Business_RoutingKey_1,"Dead Letter Hello 2203A");

        return "OK";
    }
    public int index = 0;
    @PostMapping("length/{num}")
    public String producerMessage2(@PathVariable Integer num){

        for(int i=0;i<num;i++){
            rabbitTemplate.convertAndSend(RabbitMQConfig_DeadLetter.Exchange_Business_1,
                    RabbitMQConfig_DeadLetter.Business_RoutingKey_1,"Dead Letter Hello 2109A " + index++);

        }

        return "OK";
    }


}
